//
//  JWKStatusTabBar.swift
//  Weibo
//
//  Created by 姜维克 on 16/5/25.
//  Copyright © 2016年 姜维克. All rights reserved.
//

import UIKit

class JWKStatusTabBar: UIView {
    
    var statusViewModel : JWKStatusViewModel?{
        didSet{
            
            repostsBtn.setTitle(statusViewModel?.reposts_countStr, forState: .Normal)
            commentsBtn.setTitle(statusViewModel?.comments_countStr, forState: .Normal)
            attitudesBtn.setTitle(statusViewModel?.attitudes_countStr, forState: .Normal)
            
        }
    }
    
    private let lineWidth = 1 / UIScreen.mainScreen().scale
    
    lazy var repostsBtn : UIButton = UIButton()
    lazy var commentsBtn : UIButton = UIButton()
    lazy var attitudesBtn : UIButton = UIButton()
    lazy var sepline1 : UIView = UIView()
    lazy var sepline2 : UIView = UIView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.greenColor()
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setupUI(){
        setBtn(repostsBtn, imageName: "timeline_icon_retweet", bgImageName: "timeline_card_bottom_background", title: "转发", target: nil, action: nil)
        
        setBtn(commentsBtn, imageName: "timeline_icon_comment", bgImageName: "timeline_card_bottom_background", title: "评论", target: nil, action: nil)
        
        setBtn(attitudesBtn, imageName: "timeline_icon_like", bgImageName: "timeline_card_bottom_background", title: "点赞", target: nil, action: nil)
        
        setSepline(sepline1)
        setSepline(sepline2)
        
        addSubview(repostsBtn)
        addSubview(commentsBtn)
        addSubview(attitudesBtn)
        addSubview(sepline1)
        addSubview(sepline2)
        
        repostsBtn.snp_makeConstraints { (make) in
            make.top.left.equalTo(self)
        
        }
        
        commentsBtn.snp_makeConstraints { (make) in
            make.top.equalTo(repostsBtn)
            make.left.equalTo(repostsBtn.snp_right)
            make.width.equalTo(repostsBtn)
            
        }
        
        attitudesBtn.snp_makeConstraints { (make) in
            make.top.equalTo(commentsBtn)
            make.left.equalTo(commentsBtn.snp_right)
            make.right.equalTo(self)
            make.width.equalTo(repostsBtn)
        }
        
        sepline1.snp_makeConstraints { (make) in
            make.left.equalTo(repostsBtn.snp_right)
            make.centerY.equalTo(repostsBtn)
            make.width.equalTo(lineWidth)
            make.height.equalTo(repostsBtn.bounds.height * 0.4)
            
        }
        
        sepline2.snp_makeConstraints { (make) in
            make.left.equalTo(commentsBtn.snp_right)
            make.centerY.equalTo(commentsBtn)
            make.width.equalTo(lineWidth)
            make.height.equalTo(commentsBtn.bounds.height * 0.4)
            
        }
        
        self.snp_makeConstraints { (make) in
            make.bottom.equalTo(repostsBtn)
        }
    }
    
    func setSepline(sepline:UIView){
        sepline.backgroundColor = UIColor.darkGrayColor()
    }

    func setBtn (rightBtn:UIButton, imageName : String?=nil, bgImageName : String?=nil, title : String?, target: AnyObject?, action: Selector ){
   
//    let rightBtn = UIButton()
        //设置图片
    if let img = imageName{
    rightBtn.setImage(UIImage(named: img), forState: .Normal)
    //        timeline_icon_likeee
//    rightBtn.setImage(UIImage(named: img+"ee"), forState: .Highlighted)
    }
        
    //设置背景图片
    if let bgImg = bgImageName{
        rightBtn.setBackgroundImage(UIImage(named: bgImg), forState: .Normal)
//        timeline_icon_likeee
//        rightBtn.setBackgroundImage(UIImage(named: bgImg+"ee"), forState: .Highlighted)
    }
        
    //设置背景颜色
//    rightBtn.backgroundColor = UIColor.brownColor()
        
    //设置文字
    rightBtn.setTitle(title, forState: .Normal)
    
    //设置文字颜色
    rightBtn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
//    rightBtn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
    //字体大小
    rightBtn.titleLabel?.font = UIFont.systemFontOfSize(10)
    
    //绑定点击事件
    rightBtn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
    
    rightBtn.sizeToFit()
    

    }
}
